home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 46 / Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso / -serious- / programming / other / hexy / src / hexy_wb.c < prev    next >
C/C++ Source or Header  |  1999-09-06  |  10KB  |  452 lines

  1.  
  2. /*
  3.  * [!BGN - MACHINE GENERATED - DO NOT EDIT THIS HEADER]
  4.  *
  5.  * Program   : Hexy (Binary file viewer/editor for the Amiga.)
  6.  * Version   : 1.6
  7.  * File      : Work:Source/!WIP/HisoftProjects/Hexy/Hexy_wb.c
  8.  * Author    : Andrew Bell
  9.  * Copyright : Copyright © 1998-1999 Andrew Bell (See GNU GPL)
  10.  * Created   : Saturday 28-Feb-98 16:00:00
  11.  * Modified  : Sunday 22-Aug-99 23:31:45
  12.  * Comment   : 
  13.  *
  14.  * (Generated with StampSource 1.2 by Andrew Bell)
  15.  *
  16.  * [!END - MACHINE GENERATED - DO NOT EDIT THIS HEADER]
  17.  *
  18.  */
  19.  
  20. /* Created: Sun/09/Aug/1998 */
  21.  
  22. #include <Hexy.h>
  23.  
  24. /*
  25.  *  Hexy, binary file viewer and editor for the Amiga.
  26.  *  Copyright (C) 1999 Andrew Bell
  27.  *
  28.  *  Author's email address: andrew.ab2000@bigfoot.com
  29.  *
  30.  *  This program is free software; you can redistribute it and/or modify
  31.  *  it under the terms of the GNU General Public License as published by
  32.  *  the Free Software Foundation; either version 2 of the License, or
  33.  *  (at your option) any later version.
  34.  *
  35.  *  This program is distributed in the hope that it will be useful,
  36.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  37.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38.  *  GNU General Public License for more details.
  39.  *
  40.  *  You should have received a copy of the GNU General Public License
  41.  *  along with this program; if not, write to the Free Software
  42.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  43.  *
  44.  */
  45.  
  46.  
  47. Prototype BOOL InitCX( void );
  48. Prototype void FreeCX( void );
  49. Prototype BOOL DoCxEvent( void );
  50. Prototype BOOL InitApp( void );
  51. Prototype void FreeApp( void );
  52. Prototype void KillAppIcon( void );
  53. Prototype BOOL DoIconify( void );
  54. Prototype BOOL DoAppEvent( void );
  55. Prototype ULONG CxErrCode;
  56. Prototype CxObj *CxBrok;
  57. Prototype struct MsgPort *CxMP;
  58. Prototype ULONG SigFlag_Cx;
  59. Prototype struct MsgPort *AppMP;
  60. Prototype ULONG SigFlag_App;
  61. Prototype struct AppIcon *AI;
  62. Prototype struct DiskObject *AI_GetDiskObject( void );
  63. Prototype void AI_FreeDiskObject( void );
  64.  
  65. /* Variables and data */
  66.  
  67. ULONG CxErrCode = NULL;
  68. CxObj *CxBrok = NULL;
  69. struct MsgPort *CxMP = NULL;
  70. ULONG SigFlag_Cx = NULL;
  71. struct MsgPort *AppMP = NULL;
  72. ULONG SigFlag_App = NULL;
  73. struct AppIcon *AI = NULL;
  74.  
  75. struct NewBroker CxBrokerInfo =
  76. {
  77.   NB_VERSION,
  78.   "Hexy",
  79.   VERS " Copyright © " YEAR " Andrew Bell",
  80.   "The worlds best hex viewer/editor :-)",
  81.   NBU_NOTIFY,
  82.   COF_SHOW_HIDE,   /* Flags    */
  83.   0,               /* Priority */
  84.   0,               /* Port     */
  85.   0                /* Reserved */
  86. };
  87.  
  88. BOOL InitCX( void )
  89. {
  90.   /*************************************************
  91.    *
  92.    * Setup CX releated stuff 
  93.    *
  94.    */
  95.  
  96.   CxMP = NULL;
  97.   SigFlag_Cx = NULL;
  98.  
  99.   if (CxMP = CreateMsgPort())
  100.   {
  101.     CxBrokerInfo.nb_Port = CxMP;
  102.     if (CxBrok = CxBroker((struct NewBroker *) &CxBrokerInfo,
  103.                   (LONG *) &CxErrCode))
  104.     {
  105.       ActivateCxObj( (CxObj *) CxBrok, -1L);
  106.       SigFlag_Cx = 1 << CxMP->mp_SigBit;
  107.     }
  108.     else return FALSE;
  109.   }
  110.   return TRUE;
  111. }
  112.  
  113. void FreeCX( void )
  114. {
  115.   /*************************************************
  116.    *
  117.    * Free CX related stuff
  118.    *
  119.    */
  120.  
  121.   if (CxBrok) DeleteCxObj(CxBrok);
  122.   if (CxMP) DeleteMsgPort(CxMP);
  123. }
  124.  
  125. BOOL DoCxEvent( void )
  126. {
  127.   /*************************************************
  128.   *
  129.   * Process CX releated events
  130.   *
  131.   */
  132.  
  133.   CxMsg *ThisMsg;
  134.   BOOL result = FALSE;
  135.  
  136.   while(ThisMsg = (CxMsg *) GetMsg( CxMP ) )
  137.   {
  138.     LONG CxMID = CxMsgID( (CxMsg *) ThisMsg );
  139.     ULONG CxMType = CxMsgType( (CxMsg *) ThisMsg );
  140.     ReplyMsg( (struct Message *) ThisMsg);
  141.  
  142.     /* if (CxMType == CX_INVALID) continue; */
  143.  
  144.     switch(CxMType)
  145.     {
  146.       case CXM_COMMAND:
  147.         switch(CxMID)
  148.         {
  149.           case CXCMD_UNIQUE:
  150.             break;
  151.           case CXCMD_KILL:
  152.             result = TRUE;
  153.             break;
  154.           case CXCMD_APPEAR:
  155.             if (GUIActive)
  156.             {
  157.               ScreenToFront(HexyScreen);
  158.               ActivateWindow(MAINWnd);
  159.             }
  160.             else if (ViewGUI())
  161.             {
  162.               UpdateView(&VC, NULL);
  163.               SetVDragBar(&VC);
  164.             }
  165.             else
  166.             {
  167.               ClearGUI(); DisplayBeep(NULL);
  168.             }
  169.             break;
  170.           case CXCMD_DISAPPEAR:
  171.             DoIconify();
  172.             break;
  173.         }
  174.         break;
  175.     }
  176.   }
  177.   return result;
  178. }
  179.  
  180. BOOL InitApp( void )  /* AppIcon stuff */
  181. {
  182.   /*************************************************
  183.   *
  184.   * Init Hexy AppIcon 
  185.   *
  186.   */
  187.  
  188.   AppMP = NULL;
  189.   SigFlag_App = NULL;
  190.  
  191.   if (AppMP = CreateMsgPort())
  192.   {
  193.     SigFlag_App = 1 << AppMP->mp_SigBit;
  194.   }
  195.   else return FALSE;
  196.   
  197.   AI_GetDiskObject();
  198.   
  199.   return TRUE;
  200. }
  201.  
  202. void FreeApp( void )
  203. {
  204.   /*************************************************
  205.    *
  206.    * Remove Hexy AppIcon for good 
  207.    *
  208.    */
  209.  
  210.   KillAppIcon();
  211.  
  212.   AI_FreeDiskObject();
  213.   
  214.   if (AppMP)
  215.   {
  216.     DeleteMsgPort(AppMP);
  217.     AppMP = NULL;
  218.   }
  219. }
  220.  
  221. /* Ported from FloppyFlux 1.3 in August 1999 :) */
  222.  
  223. struct DiskObject *DiskObj;
  224.  
  225. struct DiskObject *AI_GetDiskObject( void )
  226. {
  227.   /*************************************************
  228.    *
  229.    * 
  230.    *
  231.    */
  232.  
  233.   UBYTE PrgNameBuf[256+4];
  234.   BPTR PrgDirLock = GetProgramDir();
  235.   BOOL success = FALSE;
  236.   UBYTE *tmp = NULL;
  237.  
  238.   PrgNameBuf[0] = 0;
  239.  
  240.   if (PrgDirLock)
  241.   {
  242.     NameFromLock(PrgDirLock, (UBYTE *) &PrgNameBuf, 256L);
  243.  
  244.     /* Note: We don't need to unlock PrgDirLock. */
  245.   }
  246.  
  247.   /* Locate Hexy's program name */
  248.  
  249.   if (HexyWBMsg)
  250.   {
  251.     UBYTE *WBName = HexyWBMsg->sm_ArgList->wa_Name;
  252.  
  253.     if (WBName)
  254.     {
  255.       AddPart((UBYTE *) &PrgNameBuf, WBName, 256L);
  256.       
  257.       success = TRUE;
  258.     }
  259.   }
  260.   else
  261.   { 
  262.     UBYTE TmpName[128+4];
  263.     
  264.     if (GetProgramName((UBYTE *) &TmpName, 128L))
  265.     {
  266.       AddPart((UBYTE *) &PrgNameBuf, (UBYTE *) &TmpName, 256L);
  267.       
  268.       success = TRUE;
  269.     }
  270.     else HexyInformation("Failed to get program's name!", NULL);
  271.   }
  272.  
  273.   /* Load Hexy's icon and convert it to an AppIcon */
  274.  
  275.   if (success)
  276.   {
  277.     if (DiskObj = GetDiskObjectNew( (UBYTE *) &PrgNameBuf ))
  278.     {
  279.       DiskObj->do_Magic = 0;
  280.       DiskObj->do_Version = 0;
  281.       DiskObj->do_Gadget.NextGadget = NULL;
  282.       DiskObj->do_Gadget.LeftEdge = 0;
  283.       DiskObj->do_Gadget.TopEdge = 0;
  284.       DiskObj->do_Gadget.Activation = 0;
  285.       DiskObj->do_Gadget.GadgetType = 0;
  286.       ((struct Image *)DiskObj->do_Gadget.GadgetRender)->LeftEdge = 0;
  287.       ((struct Image *)DiskObj->do_Gadget.GadgetRender)->TopEdge = 0;
  288.       ((struct Image *)DiskObj->do_Gadget.GadgetRender)->PlaneOnOff = 0;
  289.       ((struct Image *)DiskObj->do_Gadget.GadgetRender)->NextImage = NULL;
  290.       DiskObj->do_Gadget.GadgetText = NULL;
  291.       DiskObj->do_Gadget.MutualExclude = 0;
  292.       DiskObj->do_Gadget.SpecialInfo = NULL;
  293.       DiskObj->do_Gadget.GadgetID = 0;
  294.       DiskObj->do_Gadget.UserData = NULL;
  295.       DiskObj->do_Type = 0;
  296.       DiskObj->do_DefaultTool = NULL;
  297.       DiskObj->do_ToolTypes = NULL;
  298.       DiskObj->do_CurrentX = NO_ICON_POSITION;
  299.       DiskObj->do_CurrentY = NO_ICON_POSITION;
  300.       DiskObj->do_DrawerData = NULL;
  301.       DiskObj->do_ToolWindow = NULL;
  302.       DiskObj->do_StackSize = 0;
  303.     }
  304.     else
  305.     {
  306.     }
  307.   }
  308.   else HexyInformation("Cannot locate program name!", NULL);
  309.  
  310.   if (!DiskObj)
  311.   {
  312.     /*HexyInformation("Failed to get AppIcon object!", NULL);*/
  313.   }
  314.  
  315.   return DiskObj;
  316. }
  317.  
  318. void AI_FreeDiskObject( void )
  319. {
  320.   /*************************************************
  321.    *
  322.    * Free the AppIcon that Hexy is using for
  323.    * iconification.
  324.    *
  325.    */
  326.  
  327.   if (DiskObj)
  328.   {
  329.     FreeDiskObject(DiskObj);
  330.     DiskObj = NULL;
  331.   }
  332. }
  333.  
  334. void KillAppIcon( void )
  335. {
  336.   /*************************************************
  337.    *
  338.    * Remove AppIcon for view 
  339.    *
  340.    */
  341.  
  342.   if (AI)
  343.   {
  344.     RemoveAppIcon(AI);
  345.     AI = NULL;
  346.   }
  347. }
  348.  
  349. BOOL DoIconify( void )
  350. {
  351.   /*************************************************
  352.    *
  353.    * Perform iconification of Hexy 
  354.    *
  355.    */
  356.  
  357.   /* Returns TRUE on success, else FALSE on failure! */
  358.  
  359.   UBYTE TempBuffer[256+4]; /* Note: this is eating up stack space */
  360.  
  361.   if (!DiskObj)
  362.   {
  363.     DisplayBeep(NULL);  /* Temp */
  364.  
  365.     HexyInformation("Cannot iconify because there is no .info file\n"
  366.                     "associated with Hexy's executable or there was\n"
  367.                     "an error while Hexy was trying to obtain it."
  368.                     "\n\n"
  369.                     "Hexy needs an .info file to create an WB AppIcon.",  NULL);
  370.     
  371.     return FALSE;
  372.   }
  373.  
  374.   AI = NULL;
  375.  
  376.   /* Get the filename */
  377.  
  378.   stream[0] = (ULONG) "<< No file loaded >>";
  379.  
  380.   if (VC.VC_FIB)
  381.   {
  382.     stream[0] = (ULONG) &VC.VC_FIB->fib_FileName;
  383.   }
  384.   RawDoFmt("Hexy: %.128s", &stream, (void *) &putChProc, &TempBuffer);
  385.  
  386.   /* Create the AppIcon */
  387.  
  388.   AI = (struct AppIcon *) AddAppIcon(NULL, NULL, (UBYTE *) &TempBuffer, AppMP, NULL, DiskObj, NULL);
  389.  
  390.   if (AI)               /* Did the AppIcon appear OK? */
  391.   {
  392.     ClearGUI();         /* If so, remove GUI! */
  393.     return TRUE;
  394.   }
  395.   else
  396.   {
  397.     DisplayBeep(NULL);  /* Temp */
  398.  
  399.     HexyInformation("Cannot iconify because Hexy was unable to create a WB AppIcon.", NULL);
  400.  
  401.     return FALSE;
  402.   }
  403. }
  404.  
  405. BOOL DoAppEvent( void ) /* This will un-iconify the Hexy GUI */
  406. {
  407.   /*************************************************
  408.    *
  409.    * Process any events related to the AppIcon 
  410.    *
  411.    */
  412.  
  413.   /* If the user double clicks the icon, then Hexy's GUI will open up
  414.      normally, else if an icon is dropped onto the AppIcon the a new
  415.      file is loaded and the GUI opened. */
  416.  
  417.   struct AppMessage *ThisMsg;
  418.  
  419.   while(ThisMsg = (struct AppMessage *) GetMsg(AppMP))
  420.   {
  421.     switch(ThisMsg->am_Type)
  422.     {
  423.       case AMTYPE_APPICON:
  424.         if (!ThisMsg->am_NumArgs && !ThisMsg->am_ArgList)
  425.         {
  426.           /* User has just double clicked AppIcon */
  427.  
  428.           if (!ViewGUI()) DisplayBeep(NULL);  /* Temp */
  429.         }
  430.         break;
  431.  
  432.       case AMTYPE_APPWINDOW:    /* Not supported yet! */
  433.       case AMTYPE_APPMENUITEM:  /* Not supported yet! */
  434.       default:
  435.         break; /* We got an unknown message type! */
  436.     }
  437.  
  438.     /*if (ThisMsg->? == CX_INVALID) continue;*/
  439.  
  440.     ReplyMsg( (struct Message *) ThisMsg);
  441.   }
  442.  
  443.   return TRUE;  /* Result not in use yet*/
  444. }
  445.  
  446. /*************************************************
  447.  *
  448.  * 
  449.  *
  450.  */
  451.  
  452.